#ifndef PREPROCESS_H
#define PREPROCESS_H
#include <stdbool.h>
#include <stdint.h>



// 更新正则表达式模式定义 - 修正版本
#define TIMESTAMP_WITH_YEAR_PATTERN "[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])[[:space:]]+([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.,][0-9]{1,3})?" // 带年份的时间戳模式
#define TIMESTAMP_MONTH_PATTERN "(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[[:space:]]+[0-9]{1,2}[[:space:]]+[0-9]{2}:[0-9]{2}:[0-9]{2}"
#define TIMESTAMP_NO_MONTH_PATTERN "[0-9]{1,2}[[:space:]]+[0-9]{2}:[0-9]{2}:[0-9]{2}"
#define HEALTHAPP_TIMESTAMP_PATTERN "[0-9]{8}-([0-1]?[0-9]|2[0-3]):([0-5]?[0-9]):([0-5]?[0-9]):[0-9]{1,3}" // HealthApp时间戳模式
#define MACTIME "[0-2][0-9]:[0-5][0-9]:[0-5][0-9]\\.[0-9]{3}"  // MAC地址模式
#define MAC_HOSTNAME_PATTERN "[a-zA-Z0-9]+(-[0-9]{1,3}){4}"
#define IP_V4V6_PATTERN "v4\\([^)]+\\) v6\\([^)]+\\)" // 同时匹配IPv4和IPv6
#define IPV6_ADDRESS_PATTERN "([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}" // IPv6地址模式
#define URL_PATTERN "\\w+://[^[:space:]]+"
#define HADOOP_TIMESTAMP_PATTERN "[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2},[0-9]{3}"  // Hadoop时间戳模式
#define IP_PATTERN "([0-9]{1,3}\\.){3}[0-9]{1,3}"
#define HOSTNAME_PATTERN "[a-zA-Z0-9][a-zA-Z0-9._-]*\\.[a-zA-Z][a-zA-Z0-9._-]**"
#define PATH_PATTERN "/[a-zA-Z0-9_./-]+"
#define HEX_PATTERN "0x[0-9a-fA-F]+"  // 十六进制数字模式
#define NULL_PATTERN "\\bnull\\b"     // null值模式
#define QUOTED_STRING_PATTERN "\"[^\"]+\""  // 引号内的字符串模式
#define EQUALS_VALUE_PATTERN "=[^, ]+"     // 等于号后面的值模式
#define NUMBER_PATTERN "[0-9]+"       // 数字序列模式
#define DECIMAL_NUMBER_PATTERN "[0-9]+\\.[0-9]+" //小数
#define WINDOWS_PATH_PATTERN "[a-zA-Z]:\\\\[^[:space:]]+"  // Windows文件路径模式  {
#define USER_PATTERN "user[[:space:]]+[^[:space:]]+"   // user后面的字符串

#define HADOOP_SPECIAL_VARS_PATTERN "\\b(app)?(attempt|job|container|task|application|blk|jvm|DFSClient)_[0-9]+_[0-9]+[a-zA-Z0-9_]*\\b"     // 简化版：匹配特定开头的Hadoop变量
#define HADOOP_SPECIAL_VARS_PATTERN2 "\\b(ask|release|newContainers|finishedContainers|resourcelimit|knownNMs|syncAction|syncMethod|syncScope|totalTime|syncDataType|syncModel|pushAction|app|who|type|path|origin|error|Code|lvl|Domain|route|url|port|unplug|date|setTodayTotalDetailSteps|totalAltitude|retries|devices|pid|time|statClient|errorCode|errorMessage|size|Type|packageName|writeStatType|uid|euid|rhost|name|phys_ram|used_ram|phys_disk|used_disk|total_vcpus|used_vcpus|pci_stats|deviceID|clientID|id|mStepsRecordManager|basicStandardStep|restartSteps)\\s*=\\s*[^[:space:]]*"     // 简化版：匹配特定开头的XXXX=
#define OPSTACK_SPECIAL_VARS_PATTERN2 ".*?-]" // OpenStack特定变量模式 t
#define OPENSTACK_UUID_PATTERN "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}" // OpenStack UUID模式

#define WINDOWS_REGISTRY_HIVE_PATH_PATTERN "\\\\\\\\\\?\\\\[^[:space:]]*"
// 预编译的正则表达式结构体
typedef struct RegexCache RegexCache;

// 初始化预处理模块
bool preprocess_init(void);
// 清理预处理模块
void preprocess_cleanup(void);
// 主预处理函数
char* preprocess_log(const char* log_line);
// 分词函数声明
char** tokenize_string(const char* str, uint32_t* token_count);
char** tokenize_template(const char* template_str, uint32_t* token_count);
void free_tokens(char** tokens, uint32_t token_count);
#endif // PREPROCESS_H
/*#ifndef PREPROCESS_H
#define PREPROCESS_H
#include <stdbool.h>
#include <stdint.h>

// 正则表达式模式定义
#define URL_PATTERN "\\w+://[^\\s]+"
#define TIMESTAMP_MONTH_PATTERN "(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\s+[0-9]{1,2} [0-9]{2}:[0-9]{2}:[0-9]{2}"
#define TIMESTAMP_NO_MONTH_PATTERN "[0-9]{1,2} [0-9]{2}:[0-9]{2}:[0-9]{2}"
#define WIN_DATETIME_PATTERN "[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}"
#define SPARK_TIME_PATTERN "[0-9]{2}/[0-9]{2}/[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}"
#define WIN_TIMESTAMP_PATTERN "[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}:[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]+"
#define IP_PATTERN "([0-9]{1,3}\\.){3}[0-9]{1,3}"
#define IPV6_PATTERN "([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])"
#define HOSTNAME_PATTERN "[a-zA-Z0-9][a-zA-Z0-9.-]*\\.[a-zA-Z0-9.-]+"
#define PATH_PATTERN "/[a-zA-Z0-9_./-]+"
#define WIN_PATH_PATTERN "[A-Za-z]:\\\\[^\\\\\\s]+"
#define GUID_PATTERN "\\{[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\\}"
#define VERSION_PATTERN "[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+"
#define HEX_PATTERN "0x[0-9a-fA-F]+"
#define WIN_ERROR_PATTERN "HRESULT = 0x[0-9a-fA-F]+"
#define USER_LIST_PATTERN "[a-zA-Z0-9_-]+(,[a-zA-Z0-9_-]+)+"
#define NUMBER_PATTERN "[0-9]+"

#define MAX_PATTERNS 17

// 预编译的正则表达式结构体
typedef struct RegexCache RegexCache;

// 初始化预处理模块
bool preprocess_init(void);
// 清理预处理模块
void preprocess_cleanup(void);
// 主预处理函数
char* preprocess_log(const char* log_line);
// 分词函数声明
char** tokenize_string(const char* str, uint32_t* token_count);
char** tokenize_template(const char* template_str, uint32_t* token_count);
void free_tokens(char** tokens, uint32_t token_count);
#endif // PREPROCESS_H
*/